﻿using Ingr.SP3D.Common.Middle.Services;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace SWS.PIP.DM
{
	public class ConfigManager
	{
		public static Dictionary<string, string> ConfigMap = GetConfig();

		private static Dictionary<string, string> GetConfig()
		{
			Dictionary<string, string> config = new Dictionary<string, string>();

			try
			{
				string strPath = MiddleServiceProvider.SiteMgr.ActiveSite.ActivePlant.PlantCatalog.SymbolShare + "\\CustomerDef\\" + Assembly.GetExecutingAssembly().GetName().Name + ".dll.config";
				XmlDocument xmlDoc = new XmlDocument();
				xmlDoc.Load(strPath);
				XmlNode majors = xmlDoc.SelectSingleNode("configuration").SelectSingleNode("MajorConfigs").SelectSingleNode("Majors");
				XmlNodeList nodeList = majors.ChildNodes;
				//遍历所有子节点
				foreach (XmlNode major in nodeList)
				{
					config[major.Attributes["Key"].Value] = major.Attributes["Value"].Value;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("读取配置错误,错误信息：" + ex.Message);
			}

			return config;
		}

		
	}
}
